package cn.yl.fxboot.application.common.config;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@EnableAsync
public class ThreadPoolConfig {

	@Bean
	public Executor customServiceExecutor() {
		ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
		// 线程核心数目
		threadPoolTaskExecutor.setCorePoolSize(5);
		threadPoolTaskExecutor.setAllowCoreThreadTimeOut(true);
		// 最大线程数
		threadPoolTaskExecutor.setMaxPoolSize(5);
		// 配置队列大小
		threadPoolTaskExecutor.setQueueCapacity(500);
		// 配置线程池前缀
		threadPoolTaskExecutor.setThreadNamePrefix("custom-service-");
		// 配置拒绝策略
		threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
		// 数据初始化
		threadPoolTaskExecutor.initialize();
		return threadPoolTaskExecutor;
	}

}
